63
Explore Your Deductive Logic—Sudoku
63
STEP 22 Continued
Next k
cantbelist = snapshotc
‘ build S2
Cells(i, j) = Right(putnumberpresent(i, j), 1)
sbox(i, j) = Cells(i, j)
Call fillemptycells
For k = 1 To 9
For l = 1 To 9
s2(k, l) = Cells(k, l)
Next l
Next k
‘ restore snapshot
For k = 1 To 9
For l = 1 To 9
Cells(k, l) = snapshot(k, l)
sbox(k, l) = snapshot(k, l)
Next l
Next k
cantbelist = snapshotc
‘compare s1 and s2
For k = 1 To 9
For l = 1 To 9
If s1(k, l) <> snapshot(k, l) And s2(k, l) = s1(k, l) Then
Cells(k, l) = s1(k, l)
sbox(k, l) = s1(k, l)
snapshot(k, l) = s1(k, l)
End If
Next l
Next k
Call RefreshCantbelist
End If
Next j
Next i
We also need these functions that are called in the code.
Sub fillemptycells()
‘first check all cells - if 8 numbers in cantbelist, then we know the number
For i = 1 To 9
For j = 1 To 9
If sbox(i, j) = ““ Then
whatisthisnumber = 0
For k = 1 To 9
If cantbelist(i, j, k) > 0 Then
howmanycantbe = k
whatisthisnumber = whatisthisnumber + cantbelist(i, j, k)
End If
Next k
If howmanycantbe = 8 Then